package com.ysqcould.web.controller.Community;


import com.ysqcould.Community.domain.VolArea;
import com.ysqcould.Community.domain.vo.VolAreaTree;
import com.ysqcould.Community.service.IVolAreaService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.domain.entity.SysDept;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 义工区域Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/Community/area")
public class VolAreaController extends BaseController
{
    @Autowired
    private IVolAreaService volAreaService;

    /**
     * 查询义工区域列表
     */
    @PreAuthorize("@ss.hasPermi('Community:area:list')")
    @GetMapping("/list")
    public AjaxResult list(VolArea volArea)
    {
        List<VolArea> list = volAreaService.selectVolAreaList(volArea);
        return AjaxResult.success(list);
    }

    /**
     * 获取义工区域下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(VolArea volArea)
    {
        List<VolArea> depts = volAreaService.selectVolAreaList(volArea);
         List<VolAreaTree> areaTrees = volAreaService.buildDeptTreeSelect(depts);

        return AjaxResult.success(areaTrees);
    }

    /**
     * 导出义工区域列表
     */
    @PreAuthorize("@ss.hasPermi('Community:area:export')")
    @Log(title = "义工区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VolArea volArea)
    {
        List<VolArea> list = volAreaService.selectVolAreaList(volArea);
        ExcelUtil<VolArea> util = new ExcelUtil<VolArea>(VolArea.class);
        util.exportExcel(response, list, "义工区域数据");
    }

    /**
     * 获取义工区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('Community:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(volAreaService.selectVolAreaById(id));
    }

    /**
     * 新增义工区域
     */
    @PreAuthorize("@ss.hasPermi('Community:area:add')")
    @Log(title = "义工区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VolArea volArea)
    {
        volArea.setAsId(getUserId());
        return toAjax(volAreaService.insertVolArea(volArea));
    }

    /**
     * 修改义工区域
     */
    @PreAuthorize("@ss.hasPermi('Community:area:edit')")
    @Log(title = "义工区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VolArea volArea)
    {
        return toAjax(volAreaService.updateVolArea(volArea));
    }

    /**
     * 删除义工区域
     */
    @PreAuthorize("@ss.hasPermi('Community:area:remove')")
    @Log(title = "义工区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(volAreaService.deleteVolAreaByIds(ids));
    }
}
